package com.lzy.pulltorefreshswipemenulistview.adapter;

import java.util.List;

import com.lzy.pulltorefreshswipemenulistview.R;
import com.lzy.pulltorefreshswipemenulistview.bean.AnyBean;
import com.lzy.pulltorefreshswipemenulistview.view.CollapsibleTextView2;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView.BufferType;

@SuppressLint("InflateParams")
public class MyAdapter extends BaseAdapter {
	private Context mCtx;
	private List<AnyBean> mList;

	public MyAdapter(Context context, List<AnyBean> list) {
		this.mCtx = context;
		this.mList = list;
	}

	@Override
	public int getCount() {
		return mList.size();
	}

	@Override
	public Object getItem(int position) {
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		if (convertView == null) {
			convertView = LayoutInflater.from(mCtx).inflate(R.layout.lv_item,
					null);
			viewHolder = new ViewHolder();
			viewHolder.ctv = (CollapsibleTextView2) convertView
					.findViewById(R.id.ctv_txt);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		AnyBean bean = mList.get(position);
		viewHolder.ctv.setDesc(bean.getTxt(), BufferType.NORMAL);

		return convertView;
	}

	class ViewHolder {
		CollapsibleTextView2 ctv;
	}

}
